package com.detu.ivos.application.controller;

import com.detu.ivos.application.pojo.dto.ApplicationQuery;
import com.detu.ivos.application.pojo.dto.ApplicationSaveParam;
import com.detu.ivos.application.pojo.entity.Application;
import com.detu.ivos.application.pojo.vo.ApplicationVO;
import com.detu.ivos.application.service.ApplicationService;
import com.detu.ivos.base.enums.ApplicationStatusEnum;
import com.detu.ivos.base.response.JsonResult;
import com.detu.ivos.vehicle.pojo.entity.Vehicle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/application/")
@Slf4j
public class ApplicationController {
    @Autowired
    ApplicationService applicationService;
    //新增申请表
    @PostMapping("save")
    public JsonResult save(ApplicationSaveParam applicationSaveParam){
        log.debug("申请单信息={}",applicationSaveParam);
        applicationService.ApplicationSave(applicationSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult select(ApplicationQuery applicationQuery){
        log.debug("查询申请单:applicationQuery={}", applicationQuery);
        List<ApplicationVO> lists=applicationService.selectApplication(applicationQuery);
        log.debug("查询申请单结果: List<ApplicationVO> lists={}", lists);
        return JsonResult.ok(lists);
    }

    @PostMapping("cancel/{id}")
    public JsonResult cancel(@PathVariable Long id){
        log.debug("撤销申请单:id={}",id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }

    @PostMapping("distribute/{applicationId}/{vehicleId}")
    public  JsonResult distribute( @PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("分配车辆id：{}，{}",applicationId,vehicleId);
        applicationService.distribute(applicationId,vehicleId);
        return JsonResult.ok();

    }

    @PostMapping("back/{applicationId}/{vehicleId}")
    public JsonResult back(
            @PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("还车:applicationId={},vehicleId={}",applicationId,vehicleId);
        applicationService.back(applicationId,vehicleId);
        return JsonResult.ok();
    }
}
